<template>
  <view class="content">
    <view class="form">
      <view class="item">
        <view class="label">
          <image class="starImg" src="../../static/img/star.png" mode=""></image>
          姓名/账号
        </view>
        <view class="ipt">
          <input type="text" placeholder="请输入姓名/账号" v-model="info.teacher_nickname">
        </view>
      </view>
      <view class="item">
        <view class="label">
          <image class="starImg" src="../../static/img/star.png" mode=""></image>
          手机号码
        </view>
        <view class="ipt">
          <input type="number" placeholder="请输入手机号码" v-model="info.teacher_phone">
        </view>
      </view>
      <view class="item">
        <view class="label">
          <image class="starImg" src="../../static/img/star.png" mode=""></image>
          就职店铺
        </view>
        <view class="ipt" @tap="schoolShow = true">
          <view class="text">
            {{schoolText}}
          </view>
          <image class="lowerImg" src="../../static/img/lowerNew.png" mode=""></image>
        </view>
      </view>

    </view>
    <view class="btn" @tap="addUser()">
      确认提交
    </view>
    <!-- 学校名称下拉框 -->
    <u-picker :show="schoolShow" :columns="schoolColumns" keyName="school_name" @confirm="confirmSchool"
      @cancel="schoolShow = false"></u-picker>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        schoolShow: false,
        schoolColumns: [],
        schoolText: "请选择就职店铺",
        sexShow: false,
        info: {
          teacher_nickname: '',
          teacher_phone: '',
          school_id: '',
        },
      };
    },
    onLoad() {
      this.getAllSchool();
    },
    methods: {
      async getAllSchool() {
        const {
          data: res
        } = await uni.$http.post('school/index/getAllSchool')
        if (res.code != 1) {
          return this.toast.msg(res.msg)
        }
        this.schoolColumns.push(res.data);
      },
      confirmSchool(e) {
        this.schoolText = e.value[0].school_name
        this.info.school_id = e.value[0].id
        this.schoolShow = false
      },
      async addUser() {
        const {
          data: res
        } = await uni.$http.post('school/teacher/addTeacher', this.info)
        if (res.code != 1) {
          return this.toast.msg(res.msg)
        }
        this.toast.msg('添加成功')
        setTimeout(() => {
          uni.navigateTo({
            url: '../coach/coach'
          })
        }, 1000)
      }
    }
  }
</script>

<style lang="scss">
  .content {
    min-height: 100vh;

    .form {
      width: 652rpx;
      margin: 40rpx auto;

      .item {
        display: flex;
        align-items: center;
        padding: 0 35rpx 0 19rpx;
        margin-bottom: 30rpx;
        width: 652rpx;
        height: 78rpx;
        line-height: 78rpx;
        border-radius: 10rpx;
        border: 2rpx solid #FCF7F7;

        .label {
          display: flex;
          align-items: center;
          font-size: 28rpx;
          margin-right: 70rpx;
          width: 160rpx;

          .starImg {
            width: 14rpx;
            height: 42rpx;
            margin-right: 15rpx;
          }
        }

        .ipt {
          flex: 1;
          position: relative;
          display: flex;
          align-items: center;
          color: #666;

          .lowerImg {
            position: absolute;
            right: 0;
            width: 20rpx;
            height: 11rpx;
          }
        }

        .time {
          color: #666;
          display: flex;
          align-items: center;

          .timeImg {
            width: 35rpx;
            height: 35rpx;
            margin-right: 17rpx;

          }
        }
      }

      .textBox {
        padding: 0 35rpx 0 19rpx;
        display: flex;
        border: 2rpx solid #FCF7F7;

        .label {
          height: 70rpx;
          display: flex;
          align-items: center;
          font-size: 28rpx;
          margin-right: 70rpx;
          width: 160rpx;

          .starImg {
            width: 14rpx;
            height: 42rpx;
            margin-right: 15rpx;
          }
        }

        .ipt {
          flex: 1;
          height: 352rpx;

          .u-textarea {
            height: 352rpx;
            border: none;
            padding-left: 0;

            /deep/.u-textarea__field {
              height: 352rpx !important;
            }

            .uni-textarea-textarea {
              height: 352rpx;
            }
          }
        }
      }
    }

    .btn {
      position: fixed;
      bottom: 50rpx;
      left: 50%;
      transform: translateX(-50%);
      width: 652rpx;
      height: 78rpx;
      line-height: 78rpx;
      text-align: center;
      background: #CCCCCC;
      border: 2rpx solid #69A1E0;
    }
  }
</style>